package com.yong.android.framework.view.recyclerview;

import android.support.annotation.IntRange;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.List;

/**
 * Description:
 * Author:yong
 * Date:2017-12-21
 */

public abstract class StatusCell<VH extends RecyclerView.ViewHolder> {
    boolean isEnable = false;
    CellListAdapter mHostAdapter;
    RecyclerView mRecyclerView;


    protected abstract RecyclerView.ViewHolder onCreateViewHolder(LayoutInflater inflater, ViewGroup parent, int viewType);

    protected abstract void onBindViewHolder(VH holder, int position);

    public abstract int getCount();

    public int getSpan(int totalSpan, int position) {
        return totalSpan;
    }

    @IntRange(from = -31, to = 31)
    public int getItemViewType(int position) {
        return 0;
    }

    public void setEnable(boolean enable) {
        if (isEnable != enable) {
            isEnable = enable;
            if (mHostAdapter != null) {
                mHostAdapter.notifyChangedDataItemDecoration(enable);
            }
        }
    }


    public final int getTotalCount() {
        return mHostAdapter == null ? -1 : mHostAdapter.getTotalCount();
    }


    protected List<RecyclerView.ItemDecoration> getItemDecorations() {
        return mHostAdapter.mItemDecorations;
    }
}
